/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/


#ifndef MK_MEDIA_CONSUMER_H
#define MK_MEDIA_CONSUMER_H
#include "MkMediaUtil.h"

class CMkMediaSource;
class MkApi CMkMediaConsumer
{
public:
    CMkMediaConsumer(const MkMediaConsumeType& ConumseType);
    virtual ~CMkMediaConsumer();
    const MkMediaConsumeType& GetConsumeType() const { return m_ConsumeType; }
    const BOOL& IsFirstSend()const { return m_bFirstSend; }
    void SetFirstSend(const BOOL& bFirstSend) { m_bFirstSend = bFirstSend; }
    void SetParentSessionId(const MkString& ParentSession) { m_ParentSession = ParentSession; }
    const MkString& GetParentSessionId() const { return m_ParentSession; }
    const MkString& GetConsumerId() const { return m_ConsumerId; }
    void SetConsumerId(const MkString& Session) { m_ConsumerId = Session; }
    virtual void Release() = 0;
    const CMkTime& GetStartTime() const { return m_StartTime; }
    const Uint64& GetSendBytes() const { return m_SendBytes; }
    void AddSendBytes(const Uint32& Bytes) { m_SendBytes += Bytes; }
protected:
private:
    MkMediaConsumeType          m_ConsumeType;
    MkString                    m_ParentSession;
    MkString                    m_ConsumerId;
    BOOL                        m_bFirstSend;
    CMkTime                     m_StartTime;
    Uint64                      m_SendBytes;
};


class CMkMediaSource;
class MkApi CMkMediaConsume
{
public:
    CMkMediaConsume(const MkMediaConsumeType& ConsumeType);
    virtual ~CMkMediaConsume();

    virtual Uint32 ConsumeEsPacket(CMkMediaSource* pSource, const MkEsPacket& EsPacket, Uint8* pBuf, Uint32 nLen) = 0;
    Uint32 AddConsumer(CMkMediaConsumer* pConsumer, const MkString& ConsumerId = "");
    Uint32 DeleteConsumer(const MkString& ConsumerId);
    Uint32 GetConsumer(const MkString& ConsumerId, CMkMediaConsumer** ppConsumer);
    void SetParentSessionId(const MkString& ParentSession) { m_ParentSession = ParentSession; }
    const MkString& GetParentSessionId() const { return m_ParentSession; }
    MkMap<MkString, CMkMediaConsumer*>& GetMapConsumer() { return m_MapConsumer; }
    BOOL IsEmpty() { return m_MapConsumer.empty(); }
    void ClearConsumer();
protected:
private:
    MkMediaConsumeType                  m_ConsumeType;
    MkString                            m_ParentSession;  //media source session
    MkMap<MkString, CMkMediaConsumer*>  m_MapConsumer;    //key consumer session
};



#endif